#define _CRT_SECURE_NO_WARNINGS
#pragma once
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#include<assert.h>
typedef int type;
typedef struct stack
{
	type* a;
	int capacity;
	int top;
}ST;
void StackInit(ST* s);
void StackPush(ST* s, type x);
bool StackEmpty(ST* s);
void StackDestory(ST* s);
void StackPop(ST* s);
type StackTop(ST* s);

void StackInit(ST* s)
{
	s->top = 0;
	s->capacity = 0;
	s->a = NULL;
}

void StackPush(ST* s, type x)
{
	assert(s);
	if (s->capacity == s->top)
	{
		//
		int newcapacity = s->capacity == 0 ? 4 : s->capacity * 2;
		type* temp = realloc(s->a, sizeof(type) * newcapacity);
		s->a = temp;
		s->capacity = newcapacity;
	}
	//Ԫ
	s->a[s->top] = x;
	s->top++;
}

bool StackEmpty(ST* s)
{
	assert(s);
	return s->top == 0;
}

void StackDestory(ST* s)
{
	assert(s);
	s->top = 0;
	s->a = NULL;
	s->capacity = 0;
}

type StackTop(ST* s)
{
	assert(s);
	assert(!StackEmpty(&s));
	return s->a[s->top-1];
}

void StackPop(ST* s)
{
	assert(s);
	assert(!StackEmpty(s));
	s->top--;
}


